Regex symbol list and regex examples

. Period, matches a single character of any single character, except the end of a line. For example, the below regex matches shirt, short and any character between sh and rt.
[code language=”text”]
sh.rt
[/code]

^ Carat, matches a term if the term appears at the beginning of a paragraph or a line. For example, the below regex matches a paragraph or a line starts with Apple.
[code language=”text”]
^Apple
[/code]

^ Carat inside a bracket, for example, the below regex matches any characters but a, b, c, d, e.
[code language=”text”]
[^a-e]
[/code]

$ Dollar sign, matches a term if the term appears at the end of a paragraph or a line. For example, the below regex matches a paragraph or a line ends with bye.
[code language=”text”]
bye$
[/code]

[ ] Square brackets, matches any single character from within the bracketed list. For example, the below regex matches bad, bed, bcd, brd, and bod.
[code language=”text”]
b[aecro]d
[/code]

– Hyphen, used for representing a range of letters or numbers,often used inside a square bracket. For example, the below regex matches kam, kbm, kcm, k2m, k3m, k4m and k5m.
[code language=”text”]
k[a-c2-5]m
[/code]

( ) Parentheses, groups one or more regular expressions. For example, the below regex matches codexpedia.com, codexpedia.net, and codexpedia.org.
[code language=”text”]
codexpedia\.(com|net|org)
[/code]

{n} Curly brackets with 1 number inside it, matches exactly n times of the preceding character. For example, the below regular expression matches 4 digits string, and only four digits string because there is ^ at the beginninga nd $ at the end of the regex.
[code language=”text”]
^[\d]{4}$
[/code]

{n,m} Curly brackets with 2 numbers inside it, matches minimum and maximum number of times of the preceding character. For example, the below regular expression matches google, gooogle and goooogle.
[code language=”text”]
go{2,4}gle
[/code]

{n,}, Curly brackets with a number and a comma, matches minimum number of times the preceding character. For example, the below regex matches google, gooogle, gooooogle, goooooogle, ….
[code language=”text”]
go{2,}gle
[/code]

| Pipe, matches either the regular expression preceding it or the regular expression following it. For example, the below regex matches the date format of MM/DD/YYYY, MM.DD.YYYY and MM-DD-YYY. It also matches MM.DD-YYYY, etc.
[code language=”text”]
^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.][0-9]{4}$
[/code]

? Question mark, matches 1 or 0 character in front of the question mark. For example, the below regular expression matches apple and apples.
[code language=”text”]
apples?
[/code]

* Asterisk, matches 0 or more characters in front of the asterisk. For example, the below regular expression matches cl,col,cool,cool,…,coooooooooool,…
[code language=”text”]
co*l
[/code]

+ Plus, matches 1 or more characters in fron of the plus. For example, the below regular expression matches col,cool,…,cooooooooooool,…
[code language=”text”]
co+l
[/code]

! Exclamation, do not matches the next character or regular expression. For example, the below regular expression matches the the characher q if the charachter after q is not a digit, it will matches the q in those strings of abdqk, quit, qeig, but not q2kd, sdkq8d.
[code language=”text”]
q(?![0-9])
[/code]

\ Backslash, turns off the special meaning of the next character. For example, the below regex treats the period as a normal character and it matches a.b only.
[code language=”text”]
a\.b
[/code]

\b Backslash and b, matches a word boundary. For example, “\bwater” finds “watergun” but not “cleanwater” whereas “water\b” finds “cleanwater” but not “watergun”.
\n Backslash and n, represents a line break.
\t Backslash and t, represents a tab.
\w Backslash and w, it is equivalent to [a-zA-Z0-9_], matches alphanumeric character or underscore. Conversely, Capital \W will match non-alphnumeric character and not underscore.
\d Backslash and d, matches digits 0 to 9, equivalent to [0-9] or [:digit]
[:alpha:] or [A-Za-z] represents an alphabetic character.
[:digit:] or [0-9] or [\d] represents a digit.
[:alnum:] or [A-Za-z0-9] represents an alphanumeric character.

This regex matches email addresses
[code language=”text”]
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b
[/code]

This regex matches websites links ending with sites of .com, .org, .edu, .gov and .us
[code language=”text”]
https?://(www\.)?[A-Za-z0-9]+\.(com|org|edu|gov|us)/?.*
[/code]

This regex matches social security numbers.
[code language=”text”]
^[0-9]{3}-[0-9]{2}-[0-9]{4}$
[/code]

Search within Codexpedia

Custom Search

Search the entire web

Custom Search